package com.yulongtian.weekCompetition.month202303.week01;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author yulongTian
 * @create 2023-03-05 11:37
 */
public class Test14 {
    public static void main(String[] args) {
        int[][] arr = {{6, 1}, {3, 2}, {2, 3}};
        System.out.println(waysToReachTarget(6, arr));
    }

    public static int waysToReachTarget(int target, int[][] types) {
        Arrays.sort(types, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1] - o2[1];
            }
        });
        List<Integer> scores = new ArrayList<>();
        for (int[] type : types) {
            for (int i = 0; i < type[0]; i++) {
                scores.add(type[1]);
            }
        }
        //双指针方法
        int left = 0;
        int sum = 0;
        int ans = 0;
        int mod = 1000000000 + 7;
        for (int right = 0; right < scores.size(); right++) {
            sum += scores.get(right);
            if (sum == target) {
                ans++;
                ans %= mod;
            }
            while (sum > target) {
                sum -= scores.get(left);
                left++;
                if (sum == target) {
                    ans++;
                    ans %= mod;
                }
            }
        }
        return ans;
    }

}
